/******************************************************************************
*
* This file is part of FreeTrack (http://code.google.com/p/qtfreetrack).
* BY Willy Gardiol (willy@gardiol.org)
*
* FreeTrack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FreeTrack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar.  If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/

#ifndef CONFIGWIDGET_H
#define CONFIGWIDGET_H

#include "IncFreeTrack.h"
#include "freetrackwidget.h"

class FTPushButton;
class OauthManager;
class FTTabWidget;
class FTHelpWidget;

class ConfigWidget : public FreeTrackWidget
{
    Q_OBJECT
public:
    explicit ConfigWidget(QWidget *parent = 0);
    ~ConfigWidget();

    // Autosave
    bool getAutosave();
    // Breadcrumbs stuff
    bool getBreadcrumbsToken(QByteArray& token, QByteArray& tokenSecret);
    bool breadcrumbsAuthorized();
    // Save initial position
    bool getSavePosition();
    QPointF getInitialPosition();
    void setInitialPosition( const QPointF& );
    // Save device screen orientation
    Orientation getOrientation();
    void setOrientation(Orientation);
    bool getSaveOrientation();
    // Require internet access authorization
    bool getInternetAuthorization();
    // Map caching support
    bool getPrecacheMaps();
    // Enable speed calculation
    bool getCalcSpeed();

    // Draw waypoint on table?
    bool getDrawWaypoint();
    // Draw waypoint icon?
    bool getDrawWaypointIcon();
    // Draw waypoint name?
    bool getDrawWaypointName();

#ifdef BUILD_FOR_OVI
    // Light always on
    bool getAlwaysOn();
#endif

    // Altitude correction
    int getAltitudeCorrection();

signals:
    void showMain();
    void autosaveChange(bool check = false);
    void savepositionChange(bool check = false);
    void breadcrumbsChange(bool check = false);
    void saveorientationChange( bool check = false);
    void precacheMapsChange( bool check = false);

public slots:
    void setModified();

private slots:
    void breadcrumbsAuthorize();
    void breadcrumbsSetpin();

    void alwaysOn( bool check );

    void altitudeCorrectionChanged(QString);

private:
    // The widgets
    FTPushButton* closeButton;

    // Autosave widget
    QCheckBox* autosave;
    // Save map position widget
    QCheckBox* saveposition;
    // Remember orientation
    QCheckBox* saveorientation;
    // Confirm internet connections
    QCheckBox* confirminternet;
    // Enable map precaching
    QCheckBox* precachemaps;

    // Enable "light always on"
    QCheckBox* always_on;

    // Enable speed calculations
    QCheckBox* calc_speed;

    // Go Breadcrumbs widgets
    QGroupBox* breadcrumbs;
    FTPushButton* breadcrumbs_authorize;
    FTPushButton* breadcrumbs_setpin;
    QLineEdit* breadcrumbs_pin;
    QByteArray breadcrumbs_token;
    QByteArray breadcrumbs_tokenSecret;
    bool breadcrumbs_authorized;
    OauthManager* breadcrumbs_oauth;
    void breadcrumbsUnauthorize();

    // Waypoint draw options
    QGroupBox* waypoints_group;
    QCheckBox* draw_waypoints;
    QCheckBox* draw_waypoints_name;
    QCheckBox* draw_waypoints_icon;

    // Altitude correction
    QGroupBox* altitude_group;
    QLineEdit* altitude;
    int altitude_correction;

    // Load configuration
    void LoadConfig();
    // Save configuration
    void SaveConfig();
    // get config filename
    QString getFilename();
    // The initial position
    QPointF initial_position;

    bool modified;
    Orientation initial_orientation;

    bool internet_confirmation_stored;
    bool internet_confirmation_value;

    QLayout* createHorizontal();
    QLayout* createVertical();

    FTTabWidget* tabs;

    QWidget* tab_general;
    FTHelpWidget* general_help;
    FTHelpWidget* waypoints_help;
    FTHelpWidget* breadcrumbs_help;

#ifdef BUILD_FOR_OVI
    QSystemScreenSaver* screen_saver;
#endif

};

#endif // CONFIGWIDGET_H
